package org.budo.java.agent.enhancer;

import org.budo.java.agent.filter.AgentFilter;
import org.budo.java.agent.filter.AgentFilterChain;
import org.budo.java.agent.filter.impl.RuntimeAgentFilterChainImpl;

/**
 * @author lmw
 */
public class AgentEnhancer {
    public static AgentFilterChain buildChain(Class<?> targetType, int methodIndex, Object target, Object[] args) {
        AgentFilter[] filters = filters();
        return new RuntimeAgentFilterChainImpl(targetType, methodIndex, target, args, filters);
    }

    private static AgentFilter[] filters() {
        AgentFilter agentFilter = new AgentFilter() {
            public void doFilter(AgentFilterChain chain) {
                System.out.println("#19 target=" + chain.getTarget());
                System.out.println("#20 method=" + chain.getMethod());
                System.out.println("#21 args=" + chain.getArgs());

                chain.doFilter();

                System.out.println("#23 result=" + chain.getResult());
            }
        };

        AgentFilter[] filters = new AgentFilter[] { agentFilter };
        return filters;
    }
}